#ifndef	__BFX_REFXMLELEMENTLIST_H__
#define	__BFX_REFXMLELEMENTLIST_H__

namespace BFX
{

//////////////////////////////////////////////////////////////////////////////

// This class represents a readonly xml element list.
class REFXMLElementList : public REFXMLNodeList
{
	friend class REFXMLDocument;
	friend class REFXMLElement;
protected:
	REFXMLElementList(REFXMLNode* pParent, const UniString& strName);
	REFXMLElementList(REFXMLNode* pParent, const UniString& strLocalName, const UniString& strNamespaceURI);
public:
	virtual ~REFXMLElementList();

	// Retrieves a node at the given index.
	virtual REFXMLNode* operator[](int iIndex) const;
	// Retrieves a node at the given index.
	virtual REFXMLNode* GetItem(int nIndex) const;
	// Gets the number of nodes in this list.
	virtual int GetCount() const;

protected:
	REFXMLNode* GetNthMatchingNode(REFXMLNode* pCurNode, bool bNext, int nCount) const;
	REFXMLNode* GetMatchingNode(REFXMLNode* pCurNode, bool bNext) const;
	// return the next element node that is in PreOrder
	REFXMLNode* NextElemInPreOrder(REFXMLNode* pCurNode) const;
	// return the previous element node that is in PreOrder
	REFXMLNode* PrevElemInPreOrder(REFXMLNode* pCurNode) const;
	// if the current node a matching element node
	bool IsMatch(REFXMLNode* pCurNode) const;

	void ConcurrencyCheck() const;

protected:
	UniString	m_strAsterisk;
	//the member vars below are saved for further reconstruction        
	UniString	m_strName;		// only one of 2 string groups will be initialized depends on which constructor is called.
	UniString	m_strLocalName; 
	UniString	m_strNamespaceURI;

	REFXMLNode*	m_pRootNode;

	// the memeber vars belwo serves the optimization of accessing of the elements in the list
	mutable int			m_nCurIndex;		// -1 means the starting point for a new search round
	mutable REFXMLNode*	m_pCurElement;		// if sets to rootNode, means the starting point for a new search round
	mutable int			m_nMatchCount;		// cached list count. -1 means it needs reconstruction
	mutable int			m_nChangeCount;		// the last document update version
};

}	//	namespace BFX

#endif	//	__BFX_REFXMLELEMENTLIST_H__
